
import 'package:flutter/material.dart';

import 'dialog_bean.dart';

class BaseDialog extends Dialog {

  BuildContext? dialogContext;
  DialogBean dialogBean;

  BaseDialog(this.dialogBean, {Key? key}) : super(key: key);

  setContext(BuildContext context){
    dialogContext = context;
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: SizedBox(
          width: 240.0,
          height: 240.0,
          child: Container(
            padding: const EdgeInsets.all(15),
            decoration: const ShapeDecoration(
              color: Colors.white,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(8.0),),
              ),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(dialogBean.title??''),
                Text(dialogBean.sunTitle??''),
                Text(dialogBean.content??''),
                Row(
                  children: [
                    InkWell(
                      child: Text(dialogBean.confirmText??''),
                      onTap: () {
                        hideDialog();
                      },
                    ),
                  ],
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  /*
   *  关闭对话框
   */
  hideDialog(){
    if(dialogContext != null) {//防止多次关闭
      Navigator.pop(dialogContext!);
      dialogContext = null;
    }
  }
}